const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');


module.exports = {
  entry: {
    app: ['babel-polyfill', path.join(__dirname, '../src/index.js')],
  },
  module: {
    rules: [
      {
        test: /\.(jsx|js)?$/,
        use: [
          {
            loader: 'thread-loader',
          },
          {
            loader: 'babel-loader',
          },
        ],
        exclude: /node_modules/,
        include: path.join(__dirname, '../src'),
      },
      {
          // exclude: [path.join(__dirname, '../node_modules')],
          test: /\.(le|c)ss$/,
          use: [
              {
                  loader: MiniCssExtractPlugin.loader,
              },
              'css-loader',
              //'postcss-loader',
              'less-loader',
          ],
      },
      {
        test: /\.(bmp|gif|png|jpg|jpeg|woff|svg|ttf|eot|pdf)\??.*$/,
        use: [
          {
            loader: 'url-loader',
            options: {
              limit: 200000,
              name: 'assets/images/[contenthash].[name].[ext]',
            },
          },
        ],
      },
    ],
  },
  plugins: [
    new webpack.optimize.ModuleConcatenationPlugin(),
    new CopyWebpackPlugin([{
        from: path.resolve(__dirname,'../public'),
        to: path.resolve(__dirname,'../dist/zj'),
        drop_console:true
    }]),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.resolve(__dirname, '../public', 'index.html'),
      hash: true,
      minify: {
        removeAttributeQuotes: true,
      },
    }),
    new MiniCssExtractPlugin({
      filename: 'assets/css/[name].[contenthash].css',
      chunkFilename: 'assets/css/[id].[contenthash].css',
    }),
  ], stats: {children:false},//'errors-only',
  resolve: {
    extensions: [".js", ".jsx", ".json"],
    alias: {
      '@': path.resolve(__dirname, '../src'),
      '~@': path.resolve(__dirname, '../src'),
      '~router': path.resolve(__dirname, '../src/router'),
      '@views': path.resolve(__dirname, '../src/views'),
      '@component': path.resolve(__dirname, '../src/components'),
      '@api': path.resolve(__dirname, '../src/api'),
      '@utils': path.resolve(__dirname, '../src/utils'),
      '@stores': path.resolve(__dirname, '../src/stores'),
    },
  },
  externals:{
      lodash:"_",
  }
}
